package net.lgpage.util;

import android.app.DownloadManager;
import android.app.DownloadManager.Request;
import android.content.Context;
import android.net.Uri;
import android.os.Environment;

public class DownloadUtil {

	public static long download(String url,String filename,String description,Context context) {
		
		DownloadManager.Request request = new DownloadManager.Request(
				Uri.parse(url));
		// 设置在什么网络情况下进行下载
		request.setAllowedNetworkTypes(Request.NETWORK_WIFI);
		// 设置通知栏标题
		request.setNotificationVisibility(Request.VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION);
		request.setTitle(filename);
		request.setDescription(description);
		request.setAllowedOverRoaming(false);
		// 设置文件存放目录
		request.setDestinationInExternalFilesDir(context, Environment.DIRECTORY_DOWNLOADS, filename);
		DownloadManager downManager = (DownloadManager)context.getSystemService(Context.DOWNLOAD_SERVICE);
		
		long id= downManager.enqueue(request);
		return id;
	}
}
